<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.4"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>miniFOC: algorithm/foc.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectlogo"><img alt="Logo" src="Acme_LOGO.png"/></td>
  <td id="projectalign">
   <div id="projectname">miniFOC<span id="projectnumber">&#160;1.0.3</span>
   </div>
   <div id="projectbrief">This open-source project aims to accomplish a FOC(Field Oriented Control) scheme that is operatable with minimum costs in China.</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.4 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_99d3723365464dd656f512988bb8dbbd.html">algorithm</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle"><div class="title">foc.h</div></div>
</div><!--header-->
<div class="contents">
<a href="foc_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno">    1</span><span class="comment">/**************************************************************************/</span></div>
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno">   10</span><span class="preprocessor">#ifndef MINIFOC_ALGORITHM_FOC_H_</span></div>
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno">   11</span><span class="preprocessor">#define MINIFOC_ALGORITHM_FOC_H_</span></div>
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno">   12</span> </div>
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno"><a class="line" href="struct_f_o_c___structure__t.html">   17</a></span><span class="keyword">typedef</span> <span class="keyword">struct </span>{</div>
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno"><a class="line" href="struct_f_o_c___structure__t.html#af832998676bd09b4198a7a7274072766">   18</a></span>    <span class="keywordtype">float</span> <a class="code hl_variable" href="struct_f_o_c___structure__t.html#af832998676bd09b4198a7a7274072766">mechanical_angle</a>;     </div>
<div class="line"><a id="l00019" name="l00019"></a><span class="lineno"><a class="line" href="struct_f_o_c___structure__t.html#af32f899f7a231c9df64a594c7b13bfa4">   19</a></span>    <span class="keywordtype">float</span> <a class="code hl_variable" href="struct_f_o_c___structure__t.html#af32f899f7a231c9df64a594c7b13bfa4">rotate_speed</a>;         </div>
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno"><a class="line" href="struct_f_o_c___structure__t.html#a483644b553c2be32ffbaf641f23c6cea">   20</a></span>    <span class="keywordtype">float</span> <a class="code hl_variable" href="struct_f_o_c___structure__t.html#a483644b553c2be32ffbaf641f23c6cea">user_expect</a>;          </div>
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno">   21</span>} <a class="code hl_struct" href="struct_f_o_c___structure__t.html">FOC_Structure_t</a>;</div>
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno">   22</span> </div>
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno"><a class="line" href="foc_8h.html#a56e6126a0ee9ac8857f6eb4cc0e720d5">   24</a></span><span class="preprocessor">#define MECHANGLE_COEFFICIENT   (6.2831854f / ENCODER_RESO)</span></div>
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno"><a class="line" href="foc_8h.html#a5446f29b725bafeb256b404b8b8107d1">   26</a></span><span class="preprocessor">#define ELECANGLE_COEFFICIENT   ((6.2831854f * POLAR_PAIRS) / ENCODER_RESO)</span></div>
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno"><a class="line" href="foc_8h.html#a2ce50cab9f20bc664e4888ffc07e656e">   28</a></span><span class="preprocessor">#define SPEED_COEFFICIENT       ((6.2831852f * TIM13_FREQUENCY) / ENCODER_RESO)</span></div>
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno">   29</span> </div>
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno">   30</span><span class="keyword">extern</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code hl_variable" href="foc_8h.html#a418bbe3f3019eaefea9f904a87cf0a05">foc_parameter_available_flag</a>;</div>
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno">   31</span><span class="keyword">extern</span> <span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code hl_variable" href="foc_8h.html#ad335385ea3909d9485703d97735b34ca">phase_sequence</a>;</div>
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno">   32</span><span class="keyword">extern</span> <span class="keyword">volatile</span> <a class="code hl_struct" href="struct_f_o_c___structure__t.html">FOC_Structure_t</a> <a class="code hl_variable" href="foc_8h.html#a6c9e1e8356380a4129a3a59d52ee1ec4">FOC_Struct</a>;</div>
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno">   33</span><span class="keywordtype">void</span> <a class="code hl_function" href="foc_8h.html#a2ee2669a464e17cfaab4e084e78c4fe1">foc_calculate_dutycycle</a>(<span class="keywordtype">float</span> elect_angle, <span class="keywordtype">float</span> d, <span class="keywordtype">float</span> q, <span class="keywordtype">float</span> *u, <span class="keywordtype">float</span> *v, <span class="keywordtype">float</span> *w);</div>
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno">   34</span><span class="keywordtype">void</span> <a class="code hl_function" href="foc_8h.html#a85fbd426ff2859593ed2b1ecd4a35d4b">foc_calibrate_phase</a>(<span class="keywordtype">void</span>);</div>
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno">   35</span> </div>
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno">   36</span><span class="preprocessor">#endif </span><span class="comment">//MINIFOC_ALGORITHM_FOC_H_</span></div>
<div class="ttc" id="afoc_8h_html_a2ee2669a464e17cfaab4e084e78c4fe1"><div class="ttname"><a href="foc_8h.html#a2ee2669a464e17cfaab4e084e78c4fe1">foc_calculate_dutycycle</a></div><div class="ttdeci">void foc_calculate_dutycycle(float elect_angle, float d, float q, float *u, float *v, float *w)</div><div class="ttdoc">calculate the corresponding three-phase PWM duty cycle under the current electrical angle</div><div class="ttdef"><b>Definition:</b> <a href="foc_8c_source.html#l00099">foc.c:99</a></div></div>
<div class="ttc" id="afoc_8h_html_a418bbe3f3019eaefea9f904a87cf0a05"><div class="ttname"><a href="foc_8h.html#a418bbe3f3019eaefea9f904a87cf0a05">foc_parameter_available_flag</a></div><div class="ttdeci">unsigned char foc_parameter_available_flag</div><div class="ttdoc">flag variable for FOC parameter availability</div><div class="ttdef"><b>Definition:</b> <a href="foc_8c_source.html#l00028">foc.c:28</a></div></div>
<div class="ttc" id="afoc_8h_html_a6c9e1e8356380a4129a3a59d52ee1ec4"><div class="ttname"><a href="foc_8h.html#a6c9e1e8356380a4129a3a59d52ee1ec4">FOC_Struct</a></div><div class="ttdeci">volatile FOC_Structure_t FOC_Struct</div><div class="ttdoc">FOC handler.</div><div class="ttdef"><b>Definition:</b> <a href="foc_8c_source.html#l00020">foc.c:20</a></div></div>
<div class="ttc" id="afoc_8h_html_a85fbd426ff2859593ed2b1ecd4a35d4b"><div class="ttname"><a href="foc_8h.html#a85fbd426ff2859593ed2b1ecd4a35d4b">foc_calibrate_phase</a></div><div class="ttdeci">void foc_calibrate_phase(void)</div><div class="ttdoc">automatic phase sequence detection and correction</div><div class="ttdef"><b>Definition:</b> <a href="foc_8c_source.html#l00033">foc.c:33</a></div></div>
<div class="ttc" id="afoc_8h_html_ad335385ea3909d9485703d97735b34ca"><div class="ttname"><a href="foc_8h.html#ad335385ea3909d9485703d97735b34ca">phase_sequence</a></div><div class="ttdeci">volatile unsigned char phase_sequence</div><div class="ttdoc">motor phase sequence flag variable</div><div class="ttdef"><b>Definition:</b> <a href="foc_8c_source.html#l00024">foc.c:24</a></div></div>
<div class="ttc" id="astruct_f_o_c___structure__t_html"><div class="ttname"><a href="struct_f_o_c___structure__t.html">FOC_Structure_t</a></div><div class="ttdoc">structure of FOC algorithm</div><div class="ttdef"><b>Definition:</b> <a href="foc_8h_source.html#l00017">foc.h:17</a></div></div>
<div class="ttc" id="astruct_f_o_c___structure__t_html_a483644b553c2be32ffbaf641f23c6cea"><div class="ttname"><a href="struct_f_o_c___structure__t.html#a483644b553c2be32ffbaf641f23c6cea">FOC_Structure_t::user_expect</a></div><div class="ttdeci">float user_expect</div><div class="ttdoc">user expect value of miniFOC</div><div class="ttdef"><b>Definition:</b> <a href="foc_8h_source.html#l00020">foc.h:20</a></div></div>
<div class="ttc" id="astruct_f_o_c___structure__t_html_af32f899f7a231c9df64a594c7b13bfa4"><div class="ttname"><a href="struct_f_o_c___structure__t.html#af32f899f7a231c9df64a594c7b13bfa4">FOC_Structure_t::rotate_speed</a></div><div class="ttdeci">float rotate_speed</div><div class="ttdoc">motor rotate speed calculate from timer</div><div class="ttdef"><b>Definition:</b> <a href="foc_8h_source.html#l00019">foc.h:19</a></div></div>
<div class="ttc" id="astruct_f_o_c___structure__t_html_af832998676bd09b4198a7a7274072766"><div class="ttname"><a href="struct_f_o_c___structure__t.html#af832998676bd09b4198a7a7274072766">FOC_Structure_t::mechanical_angle</a></div><div class="ttdeci">float mechanical_angle</div><div class="ttdoc">mechanical angle read form encoder</div><div class="ttdef"><b>Definition:</b> <a href="foc_8h_source.html#l00018">foc.h:18</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4
</small></address>
</body>
</html>
